<template>
  <div class="app-container">
      <!-- 搜索框 -->
    <el-form :inline="true" :model="searchMap.data" class="demo-form-inline">
      <el-form-item>
        <el-input
          v-model="searchMap.data.goodsName"
          placeholder="商品名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchData()">查询</el-button>
      </el-form-item>
    </el-form>
<!-- 表格列表 -->
    <el-table
      :data="goodsList"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="id" label="商品ID" width="120"> </el-table-column>
      <el-table-column prop="goodsName" label="商品名称" width="120"> </el-table-column>
      <el-table-column prop="price" label="商品价格" show-overflow-tooltip></el-table-column>
      <el-table-column prop="category1Id" label="一级分类" show-overflow-tooltip></el-table-column>
      <el-table-column prop="category2Id" label="二级分类" show-overflow-tooltip></el-table-column>
      <el-table-column prop="category3Id" label="三级分类" show-overflow-tooltip></el-table-column>
      <el-table-column prop="auditStatus" label="状态" show-overflow-tooltip>
          <template slot-scope="scope">
              <p v-if="scope.row.auditStatus==0">通过</p>
              <p v-if="scope.row.auditStatus==1">驳回</p>
              <p v-if="scope.row.auditStatus==2">申请中</p>
              <p v-if="scope.row.auditStatus==3">其他</p>
              <p v-if="scope.row.auditStatus==4">其他</p>   
          </template>
      </el-table-column>
      <el-table-column prop="" label="操作" show-overflow-tooltip fixed="right">
          <template slot-scope="scope">
              <el-button @click="handlePass(scope.row)" type="text" size="small" :disabled="scope.row.auditStatus == 0">通过</el-button>
              <el-button @click="handleReject(scope.row)" type="text" size="small" :disabled="scope.row.auditStatus == 1">驳回</el-button>
          </template>
      </el-table-column>
    </el-table>
<!-- 分页 -->
    <div class="block">
    <el-pagination
    style="float: right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchMap.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.total">
    </el-pagination>
    </div>


  </div>
</template>

<script>
import {search,update} from '@/api/goods'
export default {
  data() {
    return {
      goodsList: [],
      searchMap:{
          page:1,
          limit:5,
          data:{}
      },
      total:0,
      goods:{},
    
    };
  },
  methods:{
      //搜索
      searchData(){
          var _this=this
          search(this.searchMap).then(res=>{
              _this.goodsList=res.data
              _this.total=res.total
          })
      },
      //通过
      handlePass(row){
          var _this  =this
          this.goods.auditStatus=0
          this.goods.id=row.id
          console.log(this.goods)
            update(this.goods).then(res=>{
            _this.searchData()
            
        })
      },
      //驳回
      handleReject(row){
          var _this  =this
        this.goods.auditStatus=1
        this.goods.id=row.id
        update(this.goods).then(res=>{
            _this.searchData()
            
        })
      },
      handleSizeChange(size){
          this.searchMap.limit=size
          this.searchData()
      },
      handleCurrentChange(currentPage){
          this.searchMap.page=currentPage
           this.searchData()
      }
  },
  created(){
      
      this.searchData()
  }
};
</script>